package com.shuma.approval.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.shuma.approval.annotation.DefaultRemark;
import com.shuma.approval.dto.R;
import com.shuma.approval.service.ApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ApprovalController {

    @Autowired
    private ApprovalService approvalService;
    /**
     * 在商品详情页发起审核
     *
     * @param id
     * @return
     */
    @PostMapping("/addApproval/{id}")
    @DefaultRemark
    public R addApproval(@PathVariable Long id,@RequestParam(required = false) String remark) {
        return approvalService.add(id,remark);
    }


    /**
     * 通过审核
     * @param id
     * @return
     */
    @PostMapping("/passApproval/{id}")
    @DefaultRemark
    public R passApproval(@PathVariable Long id,@RequestParam(required = false)  String remark) {
        StpUtil.checkRole("admin");
        return approvalService.pass(id,remark);
    }

    /**
     * 驳回审核
     * @param id
     * @return
     */
    @PostMapping("/outApproval/{id}")
    @DefaultRemark
    public R outApproval(@PathVariable Long id,@RequestParam(required = false) String remark) {
        StpUtil.checkRole("admin");
        return approvalService.out(id,remark);
    }

    /**
     * 查询所有未审核商品
     */
    @GetMapping("/notApprovalGoods")
    public R notApprovalGoods() {
//        StpUtil.checkRole("admin");
        return approvalService.query();
    }
}
